<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			/*// 定义字符集-单次匹配
			//[0-9]：0到9之间任意“一个”数字
			var reg = /[0-9]/;
			var str = "2015-3-23";// ["2"]
			var str = "today is Monday 15:34";// ["1"]
			//[a-e]:表示a-e这些字符中的某一个字符
			var reg = /[a-e]/;
			var str = "hello";// ["e"]
			var reg = /[A-E]/;
			var str = "hEllo";// ["E"]
			//[a-zA-Z0-9_-]:大小写字母、数字、下划线、中划线中的某一个
			var reg = /[a-zA-Z0-9_-]/;
			var str = "%^&&_Hello-JS";// ["_"]*/
			
			//特殊字符集
			//+ : 前面那个单元出现1次或多次
			var reg = /[0-9]+/;
			var str = "hello2333-24";// ["2333"]
			var reg = /[0-9]+/g;// 全局匹配global
			var str = "hello2333-24";// ["2333", "24"]
			
			//* ：前面那个单元出现0次或者多次（任意次数）
			var reg = /go*gle/;
			var str = "gooooooooooooooogle";//["gooooooooooooooogle"]
			var str = "gogle";// ["gogle"]
			var str = "ggle";// ["ggle"]
			
			//?: 前面那个单元出现0次或1次
			var reg = /wo?rld/;
			var str = "wrld";//["wrld"]
			var str = "world";//["world"]
			var str = "woorld";//null
			
			//. :匹配除了换行符\n之外的任何一个字符  .*
			var reg = /.*/;
			var str = "^#$$#$^&458hdfihf7y80\nY*$Y$&$*#HFDIOSHF";// ["^#$$#$^&458hdfihf7y80"]
			
			//| : 两项之间的一个选项
			var reg = /milk|fish/;
			var str = "cat like eat fish and milk";//["fish"]
			
			//\ : 这个符号是用来转义
			// 把符号的特殊意义给去掉，只保留最本质的意思  \.
			var reg = /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/;
			var str = "192.168.33.4";//["192.168.33.4"]
			
			//$ ： 匹配输入字符串的结尾位置
			//^ : 匹配输入字符串的开始位置
			var reg = /^banana/;//这个正则要求banana出现在字符串的开始位置   null 
			var reg = /^monkey/;//["monkey"]
			var reg = /banana$/;//["banana"]
			var reg = /like$/;//null
			var str = "monkey and banana";
			
			var reg = /13[0-9]{9}/;
			var str = "13121212121java";
			//^和$限制被匹配的内容进行“完整匹配”，前后不再有其他的字符
			var reg = /^13[0-9]{9}$/;
			var str = "13341267121";//["13341267121"]
			
			//模式修正符组成
			//i:忽略大小写
			var reg = /[a-z]+/i;
			var str = "helloBEIJING";//["helloBEIJING"]
			//g:全局匹配global
			var reg = /[0-9]+/g;
			var str = "2018-80-20 17:40:45";//["2018", "80", "20", "17", "40", "45"]
			
			//组合字符
			// \d:表示0-9之间任意一个数字[0-9]
			var reg = /\d+/g;
			var str = "2018/8/20";//["2018", "8", "20"]
			// \D:表示非数字之一 等价于：[^0-9]
			var reg = /\D+/g;
			var str = "this is java1807%^&#$";//["this is java", "%^&#$"]
			
			// \w: 字母、数字、下划线其中一个字符,等价于:[a-zA-Z0-9_]
			// \W:非字母、数字、下划线
			var reg = /\w+/g;
			var str = "eyr89ey@gmail.com";//["eyr89ey", "gmail", "com"]
			
			// \s:表示空格Space
			// \S:表示非空格
			var reg = /\w+\s{6}\w+/;
			var str = "hello      beijing";//["hello      beijing"]
			
			// \b:表示单词的边界boundary  dhfiis issdhi  is dff
			var reg = /\bis\b/g;
			var str = "this is bread";
			var newStr = str.replace(reg, "was");
			// \B:表示非单词边界
			var reg = /\Bis\b/;
			var str = "hi is this a book";
			var newStr = str.replace(reg, "at");
			console.log(newStr);
			
			
			//限定字符
			var reg = /^13[0-9]{9}$/;
			var str = "13454545456";// ["13454545456"]
			
			//256.300.888.999
			var reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
			var reg = /(\d{1,3}\.){3}\d{1,3}/;
			
			var result = str.match(reg);
			console.log(result);
			
		</script>
	</head>
	<body>
	</body>
</html>
